/* 计算阶乘 */
#include <stdio.h>
int main(void)
{
    unsigned long res, res0;  // 20! = 2432902008176640000
    unsigned n, i;
    printf("Enter a positive integer: ");
    scanf("%u", &n);
    for (i = 0; i <= n; i++) {
        if (i == 0) {
            res = 1;
            continue;
        }
        res0 = res * i;
        if (res0 / i != res)
            break;
        res = res0;
    }
    printf("Factorial of %u: %lu\n", i - 1, res);
    return 0;
}